package com.qls.web.modules.op.controller;

import com.qls.core.entity.OpTaskStatus;
import com.qls.core.utils.R;
import com.qls.mt.api.MtRemoteService;
import com.qls.web.common.utils.PageUtils;
import com.qls.web.modules.op.service.TaskStatusService;
import com.qls.web.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


/**
 * 任务状态表（前端与服务交互）
 *
 * @author yj
 * @email yj@gmail.com
 * @date 2021-08-26 17:34:02
 */
@RestController
@RequestMapping("op/taskstatus")
public class TaskStatusController extends AbstractController {

    @Autowired
    private MtRemoteService mtRemoteService;

    @Autowired
    private TaskStatusService taskStatusService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("op:taskstatus:list")
    public R list(@RequestParam Map<String, Object> params) {
        params.put("dtId", getUserDtId());
        PageUtils page = taskStatusService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("op:taskstatus:info")
    public R info(@PathVariable("id") Integer id) {
        OpTaskStatus taskStatus = taskStatusService.getById(id);

        return R.ok().put("taskStatus", taskStatus);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("op:taskstatus:save")
    public R save(@RequestBody OpTaskStatus taskStatus) {
        taskStatusService.save(taskStatus);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("op:taskstatus:update")
    public R update(@RequestBody OpTaskStatus taskStatus) {
        taskStatusService.updateById(taskStatus);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("op:taskstatus:delete")
    public R delete(@RequestBody Integer[] ids) {
        taskStatusService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 酒店初始化
     *
     * @return R
     */
    @RequestMapping("/init")
    @RequiresPermissions("op:taskstatus:init")
    public R init() {
        Map<String, Object> map = new HashMap<>();
        map.put("dtId", getUserDtId());
        mtRemoteService.pullAll(map);
        return R.ok();
    }

}
